package nio.engine;

import java.nio.ByteBuffer;

import nio.engine.DeliverCallback;
import nio.engine.NioChannel;

public class DeliverCallbackImplementation implements DeliverCallback{

	@Override
	public void deliver(NioChannel nioChannel, ByteBuffer byteBuffer) {
		System.out.println("Message received from : " + nioChannel.getRemoteAddress() + " : " + new String(byteBuffer.array()));
		
		((NioChannelClass) nioChannel).addMsg();
		if(((NioChannelClass) nioChannel).getMsg() < 5){
			nioChannel.send(byteBuffer);
		}else{
			nioChannel.close();
		}
		
	}

}
